package com.usaas.search.component;

import com.usaas.common.exception.ServiceException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

@Slf4j
@Component
public class SmsComponent {

    private static final String TEMPLATE_CODE = "SMS_300015071";
    private static final String SIGN_NAME = "龙之辰网络";
    private static final String ACCESSKEY = "LTAI5t7T6FPS7c8NgPYqE8AB";
    private static final String SECRET = "BR9mL4eIGGpBp3EX5Lq40XH4xUzJV3";
    private static final String REGIONID = "cn-hangzhou";

    public void sendSms(String phoneNumber, String code) {
        try {
//            Map<String, String> paramMap = new HashMap<>();
//            paramMap.put("code", code);
//            String templateParam = JSON.toJSONString(paramMap);
//            DefaultProfile profile = DefaultProfile.getProfile(REGIONID, ACCESSKEY, SECRET);
//            IAcsClient client = new DefaultAcsClient(profile);
//            SendSmsRequest request = new SendSmsRequest();
//            request.setSignName(SIGN_NAME);
//            request.setTemplateCode(TEMPLATE_CODE);
//            request.setPhoneNumbers(phoneNumber);
//            request.setTemplateParam(templateParam);
//            SendSmsResponse response = client.getAcsResponse(request);
//            log.info("短信发送返回结果:{}", JSON.toJSONString(response));
        } catch (Exception e) {
            log.error("短信发送失败:{}", e);
            throw new ServiceException("短信发送失败");
        }
    }

    public static void main(String[] args) {
//        SmsComponent smsComponent = new SmsComponent();
//        smsComponent.sendSms("18773262992", "123444");
        for (int i = 0; i < 100; i++) {
            String code = String.valueOf((int) ((Math.random() * 9 + 1) * 100000));
            log.info("code：{}", code);
        }
    }
}
